﻿using Castle.DynamicProxy;

namespace Net12_AOP
{
    internal class BusiInterceptor : StandardInterceptor
    {
        protected override void PreProceed(IInvocation invocation)
        {
            Console.WriteLine($"Before {invocation.Method.Name}");
        }

        protected override void PerformProceed(IInvocation invocation)
        {
            Console.WriteLine($"{invocation.Method.Name} 执行...");
            try
            {
                base.PerformProceed(invocation);
            }
            catch (Exception e)
            {
                HandleException(e);
            }
        }

        protected override void PostProceed(IInvocation invocation)
        {
            Console.WriteLine($"After {invocation.Method.Name}");
        }

        private void HandleException(Exception exception)
        {
            Console.Error.WriteLine($"执行异常：{exception.Message}");
        }
    }
}
